// pages/physician/index.js
const App = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [{
      stepInfo: [{
          status: 0,
          pro_name: '入驻信息'
        },
        {
          status: 1,
          pro_name: '上传照片'
        },
        {
          status: 2,
          pro_name: '平台审核'
        }
      ],
      sel_icon: "../../images/right.png",
      pro_color: '#3DB969'
    }, ],
    items: [
      {value: '1', name: '男'},
      {value: '2', name: '女', checked: 'true'},
    ],
    imgList:[],
    img1:'',
    indexP:'0',
    real_name:'',
    mobile:'',
    sex:2,
    id_code:'',
    region:'',
    introduction:'',
    id_code_positive:'',
    id_code_back:'',
    real_image_url:[],
    medical_care_image_url:[],
    checkeds:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
      console.log(options)
      if(options.examine_state=='0'){
        this.setData({
          indexP:'2'
        })
      }else if(options.examine_state=='1'){
        this.setData({
          indexP:'3'
        })
      }else if(options.examine_state=='2'){
        this.setData({
          indexP:'4'
        })
      }
  },
  onToAgreement(){
    wx.navigateTo({
      url: '/packageA/pages/agreement/index',
    })
  },
  changeCheckeds(e){
    let val = e.detail.value
    if(val.length>0){
      this.setData({
        checkeds:true
      })
    }else{
      this.setData({
        checkeds:false
      })
    }
    console.log(this.data.checkeds)
  },
  bindRegionChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    console.log(e.detail.value[0],e.detail.value[1])
      this.setData({
          region: e.detail.value[0]+','+e.detail.value[1]
      })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },


  radioChange(e) {
    console.log('radio发生change事件，携带value值为：', e.detail.value)

    const items = this.data.items
    for (let i = 0, len = items.length; i < len; ++i) {
      items[i].checked = items[i].value === e.detail.value
    }

    this.setData({
      items
    })
    this.setData({
      sex:e.detail.value
    })
    console.log(this.data.sex)
  },

  toU(){
    this.setData({
      indexP:'1'
    })
  },
  Uto(){
    this.setData({
      indexP:'0'
    })
  },

  downTo(){

    if(this.data.checkeds==false){
      App.showError('请阅读勾选陪诊员协议后提交', () => {
        // wx.switchTab({
        //   url: '/pages/index/index',
        // })
      });
    }else{
      const token = wx.getStorageSync('token')
      console.log(token)
      App._post_form('accompany_info/add', {
        real_name:this.data.real_name,
        mobile:this.data.mobile,
        sex:this.data.sex,
        id_code:this.data.id_code,
        region:this.data.region,
        introduction:this.data.introduction,
        id_code_positive:this.data.id_code_positive,
        id_code_back:this.data.id_code_back,
        real_image_url:JSON.stringify(this.data.real_image_url),
        medical_care_image_url:JSON.stringify(this.data.medical_care_image_url)
      }, result => {

        console.log(result)
        this.setData({
            indexP:'2'
          }) 
      })
    }
    
   
  },
  goBtn(){
    wx.reLaunch({
      url: '/packageA/pages/end/index'
    })
  },
  goBtns(){
    this.setData({
      indexP:'0'
    })
  },
  uploadImage(e) {
    var that = this
    wx.chooseImage({
      success(res) {
        const tempFilePaths = res.tempFilePaths
        console.log(tempFilePaths)
        const token = wx.getStorageSync('token')
        console.log(token)
        wx.uploadFile({
          // url: 'https://kpz.qixiaocheng.com/index.php?s=/api/upload/image&wxapp_id=' + App.getWxappId() + '&token=' + token,
          url: 'https://cpz2.qixiaocheng.com/index.php?s=/api/upload/image&wxapp_id=' + App.getWxappId() + '&token=' + token,
          filePath: tempFilePaths[0],
          name: 'iFile',
          formData: {
            'user': 'test'
          },
          success(res) {
            const data = JSON.parse(res.data)
            console.log(data, e.currentTarget.dataset.id)
            if (data.code == '-1') {
              that.doLogin(1)
            } else {
              if(e.currentTarget.dataset.id==1){
                that.setData({
                  id_code_positive:data.data.file_path
                })
              }else if(e.currentTarget.dataset.id==2){
                that.setData({
                  id_code_back:data.data.file_path
                })
              }else if(e.currentTarget.dataset.id==3){
                  const url={
                    url:data.data.file_path
                  }
                  that.data.real_image_url.push({url:url.url})
                  that.setData({
                    real_image_url:that.data.real_image_url
                  })
                  console.log(data.data.file_path,that.data.real_image_url)
              }else if(e.currentTarget.dataset.id==4){
                  const url={
                    url:data.data.file_path
                  }
                  that.data.medical_care_image_url.push({url:url.url})
                  that.setData({
                    medical_care_image_url:that.data.medical_care_image_url
                  })
                  console.log(data.data.file_path,that.data.medical_care_image_url)
              }
              
            }
          }
        })
      }
    })
  },




  // 表单

  bindHidereal_name(e){
    this.setData({
      real_name:e.detail.value
    })
  },
  bindHidemobile(e){
    this.setData({
      mobile:e.detail.value
    })
  },
  bindHideid_code(e){
    this.setData({
      id_code:e.detail.value
    })
  },
  bindHideintroduction(e){
    this.setData({
      introduction:e.detail.value
    })
  }


  // 提交信息
})